using System;
using System.Globalization;
using System.Windows.Data;

namespace vlcplay.Converters
{
    public class AspectRatioConverter : IValueConverter
    {
        // AspectRatio property in the format "Width:Height", e.g., "16:9"
        public string AspectRatio { get; set; } = "1:1"; 

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is double width && width > 0)
            {
                var parts = AspectRatio.Split(':');
                if (parts.Length == 2 && double.TryParse(parts[0], out double ratioWidth) && double.TryParse(parts[1], out double ratioHeight) && ratioWidth > 0)
                {
                    // Calculate height based on width and aspect ratio
                    return width * (ratioHeight / ratioWidth);
                }
            }
            // Return NaN or some indicator if conversion is not possible or input is invalid
            return double.NaN;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException(); // One-way conversion
        }
    }
}